import 'package:app/pages/daily_work_report_module/his_daily_module/his_daily_view.dart';
import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:bot_toast/bot_toast.dart';

import '../../common/colors.dart';
import 'my_daily_module/my_daily_view.dart';



class MyDailyBottomTabBarPage extends StatefulWidget {
  const MyDailyBottomTabBarPage({Key? key}) : super(key: key);

  @override
  State<MyDailyBottomTabBarPage> createState() => _MyDailyBottomTabBarPageState();
}

class _MyDailyBottomTabBarPageState extends State<MyDailyBottomTabBarPage> {



  int _selectedIndex = 0;

  final List<Widget>_pageList = [

     MyDailyView(),
     HisDailyView(),
    // const HomeTable(),

  ];
  late PageController _pageController;

  var _lastTime;

  Future<bool> _isExit()async {
    if (_lastTime == null ||
        DateTime.now().difference(_lastTime) > Duration(seconds: 2)) {
      _lastTime = DateTime.now();
      print("再次点击退出应用");
      BotToast.showText(text: '再按一次退出应用');
      return Future.value(false);
    }
    return Future.value(true);
  }



  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    _pageController = PageController(initialPage: _selectedIndex);
  }

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
      onWillPop:_isExit,
      child: Scaffold(

          body: PageView(
            physics:  const NeverScrollableScrollPhysics(),
            controller: _pageController,
            children: _pageList,
          ),
          bottomNavigationBar: BrnBottomTabBar(
            fixedColor:Theme.of(context).primaryColor,
            currentIndex: _selectedIndex,
            onTap: _onItemSelected,
            // onTap: _onItemSelected,
            badgeColor: Colors.red,
            items:  [
              BrnBottomTabBarItem(icon:Image.asset('images/mydaily_icon.png',width: 20,height: 20,),title:const Text('我的日报'),
                  activeIcon: Image.asset('images/mydaily_icon.png',color: AppColor.themeColor,width: 20,height: 20,)),
              BrnBottomTabBarItem(icon: Image.asset('images/tadedaily_icon.png',width: 20,height: 20,),title:const Text('他人日报'),
                  activeIcon: Image.asset('images/tadedaily_icon.png',width: 20,height: 20,color: AppColor.themeColor,)),
              // BrnBottomTabBarItem(icon: Image.asset('images/statis_icon.png',width: 20,height: 20,),title:const Text('统计'),
              //     activeIcon: Image.asset('images/statis_icon.png',width: 20,height: 20,color: AppColor.themeColor,)),
              // BrnBottomTabBarItem(icon: Image.asset('images/set_icon.png',width: 20,height: 20,),title:const Text('设置'),
              //     activeIcon: Image.asset('images/set_icon.png',width: 20,height: 20,color: AppColor.themeColor,)),

            ],
          )
      ),
    );


  }
  _onItemSelected(int index){
    _pageController.jumpToPage(index);
    _selectedIndex = index;
    setState(() {

    });
  }
}
